﻿#!/usr/bin/env python
# ------------------------------------------------------------------------------
#
# Cell
#
# Copyright (c) 2012 Fernando Garcia Huerta
# nanomuelle@gmail.com
#
#    This file is part of SimCell
#
#    SimCell is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    SimCell is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with SimAnim.  If not, see <http://www.gnu.org/licenses/>.
#
# ------------------------------------------------------------------------------

__author__    = "$Author$"
__revision__  = "$Revision$"
__date__      = "$Date: 16 Jan 2012 $"
__copyright__ = "2012 nanomuelle.com"
__contact__   = "http://blog.nanomuelle.com"

import random

from simcell.genetic.genetic_code import GeneticCode
from simcell.cell.dna import Dna
from simcell.cell.cytoplasm import Cytoplasm

class Cell:
    """Cell class"""
    id = 0
    
    @classmethod
    def generateRandomCell(cls, num_nucleotides, g1_cycles):
        cell = Cell()
        cell.dna = Dna.generateRandomDna(num_nucleotides)
        for cicle in range(g1_cycles):
            cell.cicleG1()
        
        return cell
        
    def __init__(self):
        Cell.id = Cell.id + 1
        self.id = Cell.id

        self.dna = Dna()
        self.cytoplasm = Cytoplasm()

    def __str__(self):
        repr = "Cell %d: Dna(%s) Cytoplasm(%s)" % (self.id, str(self.dna), str(self.cytoplasm))
        return repr
        
    def __repr__(self):
        repr = "Cell %d\n" % self.id
        repr += "  Dna:\n"
        repr += "    " + "\n    ".join(self.dna.__repr__().splitlines())
        repr += "\n  Cytoplasm:\n"
        repr += "    " + "\n    ".join(self.cytoplasm.__repr__().splitlines())
        return repr
        
    def cicleG1(self):
        """Fase G1 protein generation"""
        
        # select random start point in adn to generate a rna
        rna = self.dna.transcriptRna()
        if rna:
            self.cytoplasm.addRna(rna)
            
        # Get a random rna from cytoplasm, 
        #   translate it into a protein,
        #   and store it in cytoplasm.
        rna = self.cytoplasm.extractRandomRna()
        if rna:
            protein = GeneticCode.translateRna(rna)
            if protein:
                self.cytoplasm.addProtein(protein)
        
        
        
        